import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

class ItemBean {
  //省
  String province;

  //市
  String city;

  //区
  String district;

  //详细地址
  String detailedAddress;

  //名字
  String userName;

  //电话
  String telephone;

  ItemBean(
      this.province, this.city, this.district, this.detailedAddress, this.userName, this.telephone);
}

class ShippingAddressCard extends StatelessWidget {
  final ItemBean bean;
  final Function() onClick;
  final ValueNotifier<ItemBean> value = ValueNotifier<ItemBean>(null);

  ShippingAddressCard({Key key, this.bean, this.onClick}) : super(key: key);

  void upAddress(ItemBean updata) {
    value.value = updata;
  }

  @override
  Widget build(BuildContext context) {
    value.value = bean;
    return ValueListenableProvider<ItemBean>.value(
      value: value,
      builder: (context, _) {
        ItemBean bean = context.watch<ItemBean>();
        return Card(
          elevation: 5,
          child: Container(
            child: InkWell(
              onTap: onClick,
              child: Padding(
                padding: EdgeInsets.only(left: 20.w, right: 20.w),
                child: Row(
                  children: [
                    Expanded(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(top: 30.h),
                            child: Text(
                              '${bean.province} ${bean.city} ${bean.district}',
                              style: TextStyle(fontSize: 24.sp, color: Color(0xFF333333)),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(top: 28.h),
                            child: Text(
                              bean.detailedAddress,
                              style: TextStyle(
                                fontSize: 28.sp,
                                fontWeight: FontWeight.bold,
                                color: Color(0xFF333333),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(top: 28.h, bottom: 30.h),
                            child: Text(
                              '${bean.userName}   ${bean.telephone}',
                              style: TextStyle(
                                fontSize: 24.sp,
                                color: Color(0xFF333333),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                    Image.asset(
                      'images/mine_right.png',
                      width: 30.w,
                    ),
                  ],
                ),
              ),
            ),
          ),
        );
      },
    );
  }
}
